package com.example.sign;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.HashMap;

public class MainActivity extends AppCompatActivity {

    private static MainActivity mainActivity=null;
    private  int score=0;
    private TextView tvScore;
    private Button btRecord;
    private Button stRecord;
    private GameView gameView;




    public MainActivity(){
        mainActivity=this;
    }
    public static MainActivity getMainActivity() {
        return mainActivity;
    }

    public SoundPool soundPool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);
    public HashMap<Integer, Integer> soundMap = new HashMap<Integer, Integer>();



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvScore=findViewById(R.id.tvScore);
        btRecord=findViewById(R.id.bt_record);
        stRecord=findViewById(R.id.bt_start);
        gameView = findViewById(R.id.gameView);

        soundMap.put(1, soundPool.load(this, R.raw.m1, 1));
        soundMap.put(2, soundPool.load(this, R.raw.m1, 1));

        stRecord.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                gameView.startGame();

            }
        });      //点击开始按钮调用startGame函数开始游戏

        btRecord.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,RecordActivity.class);
                startActivity(intent);
            }
        });
    }



    public void clearScore(){
        score=0;      //重新开始游戏，分数清零
        showScore();
    }
    public void showScore(){
        tvScore.setText(score+"");
    }
    public void addScore(int s){
        score+=s;
        showScore();
    }
    public int getScore(){
        return score;
    }

}
